<?php
require(dirname(__FILE__) .'/check.php');
$skin->CheckIframe();


/* **** 版权所有 ****

 程序开发：网钛科技
 网钛CMS官网：http://otcms.com
 网钛IDC官网：http://idccms.com
 ＱＱ：877873666
 微信：tudougeaini
 邮箱：877873666@qq.com

 **** 版权所有 **** */


//用户检测
$MB->Open('','login',2);


@ini_set('max_execution_time', 0);
@set_time_limit(0); 


switch ($mudi){
	case 'add':
		$menuFileID = 9;
		$MB->IsSecMenuRight('alertBack',$menuFileID,$dataType);
		AddOrRev();
		break;

	case 'rev':
		$menuFileID = 10;
		$MB->IsSecMenuRight('alertBack',$menuFileID,$dataType);
		AddOrRev();
		break;

	case 'del':
		$menuFileID = 11;
		$MB->IsSecMenuRight('alert',$menuFileID,$dataType);
		del();
		break;

	case 'moreDel':
		$menuFileID = 11;
		$MB->IsSecMenuRight('alertBack',$menuFileID,$dataType);
		MoreDel();
		break;

	case 'loadFieldInfo':
		$menuFileID = 92;
		$MB->IsSecMenuRight('alert',$menuFileID,$dataType);
		LoadFieldInfo();
		break;

	default:
		die('err');
}

$MB->Close();
$DB->Close();




// 添加、修改
function AddOrRev(){
	global $DB,$MB,$skin,$mudi,$menuFileID,$menuTreeID,$sysAdminArr,$systemArr;

	$userSysArr = Cache::PhpFile('userSys');

	$backURL		= OT::PostStr('backURL');
	$dataType		= OT::PostStr('dataType');
	$dataTypeCN		= OT::PostStr('dataTypeCN');
	$dataMode		= OT::PostStr('dataMode');
	$dataModeStr	= OT::PostStr('dataModeStr');
	$dataID			= OT::PostInt('dataID');

	$theme			= OT::PostStr('theme');
	$themeB			= OT::PostInt('themeB');
	$themeColor		= OT::PostStr('themeColor');
	$themeStyle		= '';
		if ($themeB == 1){ $themeStyle .= 'font-weight:bold;'; }
		if ($themeColor != ''){ $themeStyle .= 'color:'. $themeColor .';'; }
	$type1ID		= 0;
	$type2ID		= 0;
	$type3ID		= 0;
	$typeStr		= OT::PostStr('typeStr');
		$typeArr = explode(',',$typeStr);
		$typeArrCount=count($typeArr);
		if ($typeArrCount>=3){
			$type1ID = intval($typeArr[1]);
			if ($typeArrCount>=4){
				$type2ID = intval($typeArr[2]);
				if ($typeArrCount>=5){
					$type3ID = intval($typeArr[3]);
				}
			}
		}
	$styleBgcolor	= OT::PostStr('styleBgcolor');
	$style		= '';
		if ($styleBgcolor != ''){ $style .= 'background-color:'. $styleBgcolor .';'; }
	$tixing			= OT::PostStr('tixing');
	$note			= OT::PostStr('note');
	$rank			= OT::PostInt('rank');
	$state			= OT::PostInt('state');
	$wapState		= OT::PostInt('wapState');

	if ($theme=='' || $typeStr==''){
		JS::AlertBackEnd('表单内容接收不全.'.$theme.$typeStr);
	}

	$record=array();
	$record['IPG_theme']		= $theme;
	$record['IPG_themeStyle']	= $themeStyle;
	$record['IPG_typeStr']		= $typeStr;
	$record['IPG_type1ID']		= $type1ID;
	$record['IPG_type2ID']		= $type2ID;
	$record['IPG_type3ID']		= $type3ID;
	$record['IPG_style']		= $style;
	$record['IPG_tixing']		= $tixing;
	$record['IPG_note']			= $note;
	$record['IPG_rank']			= $rank;
	$record['IPG_state']		= $state;
	$record['IPG_wapState']		= $wapState;

	$addrec=$DB->query('select * from '. OT_dbPref .'idcProGroup where IPG_ID='. $dataID);
	if (! $row = $addrec->fetch()){
		$alertMode='新增';

		$judRes = $DB->InsertParam('idcProGroup',$record);
	}else{
		$alertMode='修改';

		$judRes = $DB->UpdateParam('idcProGroup',$record,'IPG_ID='. $dataID);
	}

	if ($judRes){
		$alertRes = '成功';
		if ($alertMode == '新增'){
			$backURL = 'idcProGroup.php?mudi=add&dataTypeCN='. urlencode('IDC产品组') .'&dataID='. $DB->GetOne('select max(IPG_ID) from '. OT_dbPref .'idcProGroup');
		}
	}else{
		$alertRes = '失败';
	}
	unset($addrec);

	Adm::AddLog(array(
		'theme'	=> $theme,
		'note'	=> '【'. $dataTypeCN .'】'. $alertMode . $alertRes .'！',
		));

	JS::AlertHrefEnd($alertMode . $alertRes .'！', $backURL);
}



// 删除
function del(){
	global $DB,$mudi,$menuFileID,$menuTreeID,$dataType,$dataTypeCN,$systemArr;

	$dataID	= OT::GetInt('dataID');
	$theme	= OT::GetStr('theme');

	$chkNum = $DB->GetOne('select count(IPD_ID) from '. OT_dbPref .'idcProData where IPD_groupID='. $dataID);
		if ($chkNum > 0){
			JS::AlertEnd('【IDC商品管理】有 '. $chkNum .' 个商品占用该组。');
		}

	$judRes = $DB->query('delete from '. OT_dbPref .'idcProGroup where IPG_ID='. $dataID);
	if ($judRes == true){
		$alertRes = '成功';
	}else{
		$alertRes = '失败';
	}

	Adm::AddLog(array(
		'theme'	=> $theme,
		'note'	=> '【'. $dataTypeCN .'】删除'. $alertRes .'！',
		));

	echo('
	<script language="javascript" type="text/javascript">
	parent.$id("data'. $dataID .'").style.display="none";
	</script>
	');
}



// 批量删除
function MoreDel(){
	global $DB,$mudi,$menuFileID,$menuTreeID,$systemArr;

	$backURL	= OT::PostStr('backURL');
	$dataType	= OT::PostStr('dataType');
	$dataTypeCN	= OT::PostStr('dataTypeCN');
	$selDataID	= OT::Post('selDataID');

	$selCount = OT::NewCount($selDataID);
	if ($selCount <= 0){
		JS::AlertBackEnd('请先选择要删除的记录.');
	}

	$whereStr = '';
	for ($i=0; $i<$selCount; $i++){
		$whereStr .= ','. intval($selDataID[$i]);
	}
	if ($whereStr == ''){
		JS::AlertBackEnd('请先选择要删除的记录.');
	}

	JS::AlertBackEnd('批量删除功能暂时不支持。');

	$judRes = $DB->query('delete from '. OT_dbPref .'idcProGroup where IPG_ID in (0'. $whereStr .')');

	Adm::AddLog(array(
		'note'		=> '【'. $dataTypeCN .'】批量删除完成！',
		));

	JS::AlertHrefEnd('批量删除完成.',$backURL);

}
?>